/**
 * Created by Ysssssss on 2021/5/18.
 */
import { put, takeEvery } from 'redux-saga/effects'
import apiType, {
    ADD_WECHAT_MINI_TESTER,
    DELETE_WECHAT_MINI_TESTER,
    AUTHORIZATION_WECHAT,
    COMMIT_WECHAT_MINI,
    GET_WECHAT_MINI_INFO,
    GET_WECHAT_MINI_TEST_QR_CODE,
    GET_WECHAT_MINI_VERSION_LOGS,
    GET_WECHAT_PRE_AUTH_CODE,

    GET_WECOM_BIZ_BIND,
    SET_WECOM_BIZ_BIND,
    LIST_WECOM_CORP_SUITES,
    GET_WECOM_AUTHORIZE_SUITE_QR_CODE,

    GET_ALIPAY_MINI_INFO,
    AUTHORIZATION_ALIPAY,
    GET_ALIPAY_MINI_TEST_QR_CODE,
    ADD_ALIPAY_MINI_TESTER,
    DELETE_ALIPAY_MINI_TESTER,
    GET_ALIPAY_MINI_VERSION_LOGS,
    COMMIT_ALIPAY_MINI,
    ADD_ALIPAY_MINI_INFO,

    GET_BYTEDANCE_MINI_INFO,
    AUTHORIZATION_BYTEDANCE,
    GET_BYTEDANCE_PRE_AUTH_CODE,
    GET_BYTEDANCE_MINI_TEST_QR_CODE,
    GET_BYTEDANCE_MINI_VERSION_LOGS,
    COMMIT_BYTEDANCE_MINI, CREATE_CUSTOMIZE_MINI_CODE,
} from "@constants/ActionTypes";
import {getAxios, postAxios} from "@utils/api";
import notify from "@utils/tip";
import axios from "axios";
import {PLATFORM_MAP} from "@constants/PlatformList";
import { all, call } from 'redux-saga/effects'


/**
 * 获取微信小程序信息
 * @param successCallback
 * @param failureCallback
 * @returns {{successCallback: *, failureCallback: *, type: string}}
 */
export const getWechatMiniInfo = (successCallback, failureCallback) => ({
    type: apiType(GET_WECHAT_MINI_INFO).request,
    successCallback,
    failureCallback
})

/**
 * 获取授权跳转参数信息
 * @param callback
 * @returns {{callback: *, type: string}}
 */
export const getWechatPreAuthCode = (callback) => ({
    type: apiType(GET_WECHAT_PRE_AUTH_CODE).request,
    callback
})

/**
 * 微信授权审核
 * @param authorizationCode
 * @param callback
 * @returns {{callback: *, type: string, params: {authorizationCode: *}}}
 */
export const authorizeWechat = ({ authorizationCode }, callback) => ({
    type: apiType(AUTHORIZATION_WECHAT).request,
    params: { authorizationCode },
    callback
})

/**
 * 获取微信体验二维码
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}}}
 */
export const getWechatMiniTestQRCode = (callback) => ({
    type: apiType(GET_WECHAT_MINI_TEST_QR_CODE).request,
    callback
})

/**
 * 增加微信体验者
 * @param wechatId
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {wechatId: *}}}
 */
export const addWechatMiniTester = ({ wechatId }, callback) => ({
    type: apiType(ADD_WECHAT_MINI_TESTER).request,
    params: { wechatId },
    callback
})

/**
 * 删除微信体验者
 * @param wechatId
 * @param userString
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {wechatId: *, userString: *}}}
 */
export const deleteWechatMiniTester = ({ wechatId, userString }, callback) => ({
    type: apiType(DELETE_WECHAT_MINI_TESTER).request,
    params: { wechatId, userString },
    callback
})

/**
 * 获取微信发布版本信息
 * @param pageNo
 * @param pageSize
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {pageSize: *, pageNum: *}}}
 */
export const getWechatMiniVersionLogs = ({ pageNo, pageSize }, callback) => ({
    type: apiType(GET_WECHAT_MINI_VERSION_LOGS).request,
    params: { pageNum: pageNo, pageSize },
    callback
})

/**
 * 微信小程序提交审核
 * @param callback
 * @returns {{callback: *, type: string}}
 */
export const commitWechatMini = (callback) => ({
    type: apiType(COMMIT_WECHAT_MINI).request,
    callback
})

/**
 * 获取企业微信业务绑定
 * @param params
 * @param successCallback
 * @param failureCallback
 * @returns {{params: {}, successCallback: *, failureCallback: *, type: string}}
 */
 export const getWecomBizBind = (params, successCallback, failureCallback) => ({
    type: apiType(GET_WECOM_BIZ_BIND).request,
    params,
    successCallback,
    failureCallback
})

/**
 * 设置企业微信业务绑定
 * @param params
 * @param successCallback
 * @returns {{params: {}, successCallback: *, type: string}}
 */
 export const setWecomBizBind = (params, successCallback) => ({
    type: apiType(SET_WECOM_BIZ_BIND).request,
    params,
    successCallback
})

/**
 * 获取企业微信的第三方应用列表(包括未授权的和已授权的)
 * @param params
 * @param successCallback
 * @returns {{params: {}, successCallback: *, type: string}}
 */
 export const listWecomCorpSuites = (params, successCallback) => ({
    type: apiType(LIST_WECOM_CORP_SUITES).request,
    params,
    successCallback
})

/**
 * 获取企业微信第三方应用授权二维码
 * @param params
 * @param successCallback
 * @returns {{params: {}, successCallback: *, type: string}}
 */
 export const getWecomSuiteAuthorizeQRCode = (params, successCallback) => ({
    type: apiType(GET_WECOM_AUTHORIZE_SUITE_QR_CODE).request,
    params,
    successCallback
})

/**
 * 获取支付宝小程序信息
 * @param successCallback
 * @param failureCallback
 * @returns {{successCallback: *, failureCallback: *, type: string}}
 */
export const getAlipayMiniInfo = (successCallback, failureCallback) => ({
    type: apiType(GET_ALIPAY_MINI_INFO).request,
    successCallback,
    failureCallback
})

/**
 * 补充支付宝小程序审核信息
 * @param params
 * @param callback
 * @returns {{callback: *, type: string, params: *}}
 */
export const addAlipayMiniInfo = (params, callback) => ({
    type: apiType(ADD_ALIPAY_MINI_INFO).request,
    params,
    callback
})

/**
 * 支付宝授权审核
 * @param appAuthCode
 * @param callback
 * @returns {{callback: *, type: string, params: {authorizationCode: *}}}
 */
export const authorizeAlipay = ({ appAuthCode }, callback) => ({
    type: apiType(AUTHORIZATION_ALIPAY).request,
    params: { appAuthCode },
    callback
})

/**
 * 获取支付宝体验二维码
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}}}
 */
export const getAlipayMiniTestQRCode = (callback) => ({
    type: apiType(GET_ALIPAY_MINI_TEST_QR_CODE).request,
    callback
})

/**
 * 增加支付宝体验者
 * @param userId
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {wechatId: *}}}
 */
export const addAlipayMiniTester = ({ userId }, callback) => ({
    type: apiType(ADD_ALIPAY_MINI_TESTER).request,
    params: { userId },
    callback
})

/**
 * 删除支付宝体验者
 * @param userId
 * @param callback
 * @returns {{callback: *, type: string, params: {userId: *}}}
 */
export const deleteAlipayMiniTester = ({ userId }, callback) => ({
    type: apiType(DELETE_ALIPAY_MINI_TESTER).request,
    params: { userId },
    callback
})

/**
 * 获取支付宝发布版本信息
 * @param pageNo
 * @param pageSize
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {pageSize: *, pageNum: *}}}
 */
export const getAlipayMiniVersionLogs = ({ pageNo, pageSize }, callback) => ({
    type: apiType(GET_ALIPAY_MINI_VERSION_LOGS).request,
    params: { pageNum: pageNo, pageSize },
    callback
})

/**
 * 支付宝小程序提交审核
 * @param callback
 * @returns {{callback: *, type: string}}
 */
export const commitAlipayMini = (callback) => ({
    type: apiType(COMMIT_ALIPAY_MINI).request,
    callback
})


/**
 * 获取字节跳动小程序信息
 * @param successCallback
 * @param failureCallback
 * @returns {{successCallback: *, failureCallback: *, type: string}}
 */
export const getBytedanceMiniInfo = (successCallback, failureCallback) => ({
    type: apiType(GET_BYTEDANCE_MINI_INFO).request,
    successCallback,
    failureCallback
})

/**
 * 获取授权跳转参数信息
 * @param callback
 * @returns {{callback: *, type: string}}
 */
export const getBytedancePreAuthCode = (callback) => ({
    type: apiType(GET_BYTEDANCE_PRE_AUTH_CODE).request,
    callback
})

/**
 * 字节跳动授权审核
 * @param appId
 * @param authorizationCode
 * @param expiresIn
 * @param callback
 * @returns {{callback: *, type: string, params: {authorizationCode: *}}}
 */
export const authorizeBytedance = ({ authorizationCode, expiresIn }, callback) => ({
    type: apiType(AUTHORIZATION_BYTEDANCE).request,
    params: { authorizationCode, expiresIn },
    callback
})

/**
 * 获取字节跳动体验二维码
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}}}
 */
export const getBytedanceMiniTestQRCode = (callback) => ({
    type: apiType(GET_BYTEDANCE_MINI_TEST_QR_CODE).request,
    callback
})

/**
 * 获取字节跳动发布版本信息
 * @param pageNo
 * @param pageSize
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {pageSize: *, pageNum: *}}}
 */
export const getBytedanceMiniVersionLogs = ({ pageNo, pageSize }, callback) => ({
    type: apiType(GET_BYTEDANCE_MINI_VERSION_LOGS).request,
    params: { pageNum: pageNo, pageSize },
    callback
})

/**
 * 字节跳动小程序提交审核
 * @param callback
 * @returns {{callback: *, type: string}}
 */
export const commitBytedanceMini = (callback) => ({
    type: apiType(COMMIT_BYTEDANCE_MINI).request,
    callback
})

export const createCustomizeMiniCode = ({ path, query, codeKey }, callback) => ({
    type: apiType(CREATE_CUSTOMIZE_MINI_CODE).request,
    params: { path, query, codeKey },
    callback
})


const sagas = {
    * [apiType(GET_WECHAT_MINI_INFO).request] ({ successCallback, failureCallback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/wechat', {}, true)
            yield put({ type: apiType(GET_WECHAT_MINI_INFO).success, response });
            successCallback && successCallback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WECHAT_MINI_INFO).failure });
            const { error_message, reason } = e
            if (reason === 'AUTH_NOT_FOUND') {
                failureCallback && failureCallback(reason)
            } else if (reason === 'AUTH_UNAUTHORIZED') {
                notify(error_message)
                failureCallback && failureCallback(reason)
            } else {
                notify(error_message)
            }
        }
    },
    * [apiType(GET_WECHAT_PRE_AUTH_CODE).request] ({ callback }) {
        try {
            const response = yield getAxios('/open/admin/v1/wechat/pre_auth_code')
            yield put({ type: apiType(GET_WECHAT_PRE_AUTH_CODE).success, response });
            callback && callback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WECHAT_PRE_AUTH_CODE).failure });
        }
    },
    * [apiType(AUTHORIZATION_WECHAT).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/wechat/authorize', params)
            yield put({ type: apiType(AUTHORIZATION_WECHAT).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(AUTHORIZATION_WECHAT).failure });
        }
    },
    * [apiType(GET_WECHAT_MINI_TEST_QR_CODE).request] ({ callback }) {
        try {
            const response = yield axios({
                method: 'GET',
                url: `/open/admin/v1/mini/wechat/test_qr_code`,
            })
            yield put({ type: apiType(GET_WECHAT_MINI_TEST_QR_CODE).success, response: `data:${response.content_type};base64,${response.content}` });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_WECHAT_MINI_TEST_QR_CODE).failure });
        }
    },
    * [apiType(ADD_WECHAT_MINI_TESTER).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/wechat/testers', params)
            yield put({ type: apiType(ADD_WECHAT_MINI_TESTER).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(ADD_WECHAT_MINI_TESTER).failure });
        }
    },
    * [apiType(DELETE_WECHAT_MINI_TESTER).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/wechat/tester:delete', params)
            yield put({ type: apiType(DELETE_WECHAT_MINI_TESTER).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(DELETE_WECHAT_MINI_TESTER).failure });
        }
    },
    * [apiType(GET_WECHAT_MINI_VERSION_LOGS).request] ({ params, callback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/wechat/version_logs', params)
            yield put({ type: apiType(GET_WECHAT_MINI_VERSION_LOGS).success, response, params });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_WECHAT_MINI_VERSION_LOGS).failure });
        }
    },
    * [apiType(COMMIT_WECHAT_MINI).request] ({ callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/wechat/commit')
            yield put({ type: apiType(COMMIT_WECHAT_MINI).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(COMMIT_WECHAT_MINI).failure });
        }
    },

    * [apiType(GET_WECOM_BIZ_BIND).request] ({params, successCallback, failureCallback }) {
        try {
            const response = yield getAxios('/of-open/biz_bind', params, true)
            yield put({ type: apiType(GET_WECOM_BIZ_BIND).success, response });
            successCallback && successCallback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WECOM_BIZ_BIND).failure });
            const { data } = e
            failureCallback && failureCallback(data)
        }
    },

    * [apiType(SET_WECOM_BIZ_BIND).request] ({params, successCallback }) {
        try {
            console.warn("------> setWecomBizBind=>",params)
            const response = yield postAxios('/of-open/biz_bind', params)
            yield put({ type: apiType(SET_WECOM_BIZ_BIND).success, response });
            successCallback && successCallback(response)
        } catch (e) {
            yield put({ type: apiType(SET_WECOM_BIZ_BIND).failure }); 
        }
    },

    * [apiType(LIST_WECOM_CORP_SUITES).request] ({params, successCallback }) {
        try {
            const response = yield getAxios('/of-open/suites', params)
            yield put({ type: apiType(LIST_WECOM_CORP_SUITES).success, response });
            successCallback && successCallback(response)
        } catch (e) {
            yield put({ type: apiType(LIST_WECOM_CORP_SUITES).failure }); 
        }
    },

    * [apiType(GET_WECOM_AUTHORIZE_SUITE_QR_CODE).request] ({params, successCallback }) {
        try {
            const url = `/of-open/suite/${params.suite_id}/auth_url`
            const response = yield postAxios(url, {"corp_id": params.corp_id})
            yield put({ type: apiType(GET_WECOM_AUTHORIZE_SUITE_QR_CODE).success, response });
            successCallback && successCallback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WECOM_AUTHORIZE_SUITE_QR_CODE).failure }); 
        }
    },
    
    
    * [apiType(GET_ALIPAY_MINI_INFO).request] ({ successCallback, failureCallback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/alipay', {}, true)
            yield put({ type: apiType(GET_ALIPAY_MINI_INFO).success, response });
            successCallback && successCallback()
        } catch (e) {
            yield put({ type: apiType(GET_ALIPAY_MINI_INFO).failure });
            const { error_message, reason = '' } = e
            if (reason === 'AUTH_NOT_FOUND') {
                failureCallback && failureCallback(reason)
            } else if (reason === 'AUTH_UNAUTHORIZED') {
                notify(error_message)
                failureCallback && failureCallback(reason)
            } else {
                notify(error_message)
            }
        }
    },
    * [apiType(AUTHORIZATION_ALIPAY).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/alipay/authorize', params)
            yield put({ type: apiType(AUTHORIZATION_ALIPAY).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(AUTHORIZATION_ALIPAY).failure });
        }
    },
    * [apiType(GET_ALIPAY_MINI_TEST_QR_CODE).request] ({ callback }) {
        try {
            const response = yield axios({
                method: 'GET',
                url: `/open/admin/v1/mini/alipay/test_qr_code`,
            })
            yield put({ type: apiType(GET_WECHAT_MINI_TEST_QR_CODE).success, response: `data:${response.content_type};base64,${response.content}` });

            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_ALIPAY_MINI_TEST_QR_CODE).failure });
        }
    },
    * [apiType(ADD_ALIPAY_MINI_TESTER).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/alipay/testers', params)
            yield put({ type: apiType(ADD_ALIPAY_MINI_TESTER).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(ADD_ALIPAY_MINI_TESTER).failure });
        }
    },
    * [apiType(DELETE_ALIPAY_MINI_TESTER).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/alipay/tester:delete', params)
            yield put({ type: apiType(DELETE_ALIPAY_MINI_TESTER).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(DELETE_ALIPAY_MINI_TESTER).failure });
        }
    },
    * [apiType(GET_ALIPAY_MINI_VERSION_LOGS).request] ({ params, callback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/alipay/version_logs', params)
            yield put({ type: apiType(GET_ALIPAY_MINI_VERSION_LOGS).success, response, params });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_ALIPAY_MINI_VERSION_LOGS).failure });
        }
    },
    * [apiType(COMMIT_ALIPAY_MINI).request] ({ callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/alipay/commit')
            yield put({ type: apiType(COMMIT_ALIPAY_MINI).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(COMMIT_ALIPAY_MINI).failure });
        }
    },



    * [apiType(GET_BYTEDANCE_MINI_INFO).request] ({ successCallback, failureCallback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/bytedance', {}, true)
            yield put({ type: apiType(GET_BYTEDANCE_MINI_INFO).success, response });
            successCallback && successCallback()
        } catch (e) {
            yield put({ type: apiType(GET_BYTEDANCE_MINI_INFO).failure });
            const { error_message, reason = '' } = e
            if (reason === 'AUTH_NOT_FOUND') {
                failureCallback && failureCallback(reason)
            } else if (reason === 'AUTH_UNAUTHORIZED') {
                notify(error_message)
                failureCallback && failureCallback(reason)
            } else {
                notify(error_message)
            }
        }
    },
    * [apiType(GET_BYTEDANCE_PRE_AUTH_CODE).request] ({ callback }) {
        try {
            const response = yield getAxios('/open/admin/v1/bytedance/pre_auth_code')
            yield put({ type: apiType(GET_BYTEDANCE_PRE_AUTH_CODE).success, response });
            callback && callback(response)
        } catch (e) {
            yield put({ type: apiType(GET_BYTEDANCE_PRE_AUTH_CODE).failure });
        }
    },
    * [apiType(AUTHORIZATION_BYTEDANCE).request] ({ params, callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/bytedance/authorize', params)
            yield put({ type: apiType(AUTHORIZATION_BYTEDANCE).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(AUTHORIZATION_BYTEDANCE).failure });
        }
    },
    * [apiType(GET_BYTEDANCE_MINI_TEST_QR_CODE).request] ({ callback }) {
        try {
            const response = yield axios({
                method: 'GET',
                url: `/open/admin/v1/mini/bytedance/test_qr_code`,
            })
            yield put({ type: apiType(GET_WECHAT_MINI_TEST_QR_CODE).success, response: `data:${response.content_type};base64,${response.content}` });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_BYTEDANCE_MINI_TEST_QR_CODE).failure });
        }
    },
    * [apiType(GET_BYTEDANCE_MINI_VERSION_LOGS).request] ({ params, callback }) {
        try {
            const response = yield getAxios('/open/admin/v1/mini/bytedance/version_logs', params)
            yield put({ type: apiType(GET_BYTEDANCE_MINI_VERSION_LOGS).success, response, params });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(GET_BYTEDANCE_MINI_VERSION_LOGS).failure });
        }
    },
    * [apiType(COMMIT_BYTEDANCE_MINI).request] ({ callback }) {
        try {
            const response = yield postAxios('/open/admin/v1/mini/bytedance/commit')
            yield put({ type: apiType(COMMIT_BYTEDANCE_MINI).success, response });
            callback && callback()
        } catch (e) {
            yield put({ type: apiType(COMMIT_BYTEDANCE_MINI).failure });
        }
    },
    * [apiType(CREATE_CUSTOMIZE_MINI_CODE).request] ({ params, callback }) {
        const { path, query, codeKey } = params
        yield all([
            createWechatMiniCode({ path, query, codeKey }),
            createAlipayMiniCode({ path, query, codeKey }),
            createBytedanceMiniCode({ path, query, codeKey }),
        ])
        callback && callback()
    },
}

function* createWechatMiniCode({ path, query, codeKey }) {
    try {
        const response = yield postAxios('/open/admin/v1/mini/wechat/qr_code', {
            page: path,
            scene: query
        }, true)
        yield put({
            type: apiType(CREATE_CUSTOMIZE_MINI_CODE).success,
            response: `data:${response.content_type};base64,${response.content}`,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.wechat
            }
        })
    } catch (e) {
        yield put({ type: apiType(CREATE_CUSTOMIZE_MINI_CODE).failure,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.wechat
            }
        });
    }
}
function* createAlipayMiniCode({ path, query, codeKey }) {
    try {
        const response = yield postAxios('/open/admin/v1/mini/alipay/qr_code', {
            url_param: path,
            query_param: query,
            describe: '小程序码'
        }, true)
        yield put({
            type: apiType(CREATE_CUSTOMIZE_MINI_CODE).success,
            response: response.qr_code_url,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.alipay
            }
        })
    } catch (e) {
        yield put({ type: apiType(CREATE_CUSTOMIZE_MINI_CODE).failure,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.alipay
            }
        });
    }
}
function* createBytedanceMiniCode({ path, query, codeKey }) {
    try {
        const response = yield postAxios('/open/admin/v1/mini/bytedance/qr_code', {
            app_name: 'douyin',
            path: encodeURIComponent(`${path}?${query}`)
        }, true)
        yield put({
            type: apiType(CREATE_CUSTOMIZE_MINI_CODE).success,
            response: `data:${response.content_type};base64,${response.content}`,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.bytedance
            }
        })
    } catch (e) {
        yield put({ type: apiType(CREATE_CUSTOMIZE_MINI_CODE).failure,
            payload: {
                codeKey,
                platformId: PLATFORM_MAP.bytedance
            }
        });
    }
}

export default Object.keys(sagas).map(item => {
    return function * s() {
        yield takeEvery(item, function *(args) {
            try {
                yield sagas[item](args)
            } catch (e) {
                console.log(e)
            }
        })
    }
})